/*
 * Jamus
 * Copyright (C) 2010 Jamus Team
 *
 * Jamus is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Jamus is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Jamus.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * QTrackListAdaptor.cpp
 *
 *  Created on: Feb 3, 2010
 *      Author: christian moellinger
 */

#include "QTrackListAdaptor.h"

//std::vector<Track> tracklist;

QTrackListAdaptor::QTrackListAdaptor(QObject *parent) :
	QDBusAbstractAdaptor(parent), logger(log4cxx::Logger::getLogger(
			"frontend.amarok.Plugin.TrackListAdaptor")), backend(
					dynamic_cast<QFunctionWrapper *> (parent)->backendPlugin)
{

}

int QTrackListAdaptor::AddTrack(QString name, bool)
{
	LOG4CXX_ERROR(logger,"(int) AddTrack(QString, bool) not implemented yet");
	return 0;
}

void QTrackListAdaptor::DelTrack(int index)
{
	LOG4CXX_ERROR(logger,"(void) DelTrack(int) not implemented yet");
}

int QTrackListAdaptor::GetCurrentTrack()
{
	try {
		return backend.getCurrentTrack();
	}
	catch (std::exception &e)
	{
		return 0;
	}
}

int QTrackListAdaptor::GetLength()
{

	return backend.getPlaylist().size();
}

QVariantMap QTrackListAdaptor::GetMetadata(int index)
{
	boost::lock_guard<boost::mutex> lock(mutex);

	try {
	std::vector<Track> tracklist = backend.getPlaylist();
	int currentId = index;
	Track currentTrack = tracklist.at(currentId);

	QVariantMap currentTrackMapped;
	currentTrackMapped.insert("artist", QString(
			currentTrack.getArtist().c_str()));
	currentTrackMapped.insert("title", QString(currentTrack.getTitle().c_str()));
	currentTrackMapped.insert("album", QString(currentTrack.getAlbum().c_str()));
	return currentTrackMapped;
	}
	catch (std::exception *e)
	{
		return QVariantMap();
	}
}

void QTrackListAdaptor::SetLoop(bool on)
{
	LOG4CXX_ERROR(logger,"(void) SetLoop(bool) not implemented yet");
}

void QTrackListAdaptor::SetRandom(bool on)
{
	LOG4CXX_ERROR(logger,"(void) SetRandom(bool) not implemented yet");
}
